package notifiers;

import java.util.List;
import java.util.Map;

/**
 * Class is handling composing email notifications for specific situations.
 */
public class MailBuilder {

    /**
     * Compose email sent as notification for Rss-type base.
     *
     * @param channelsMap Map containing number of new entries in each channel.
     * @param base Name of the notified base.
     * @return String with message for an Email.
     */
    public static String composeRssNotification(
            Map<String, Integer> channelsMap, String baseName) {
        StringBuilder message = new StringBuilder();
        int mapSize = channelsMap.size();
        message.append("You've got new entries in ");
        message.append(mapSize);
        message.append((mapSize == 1) ? " channel " : " channels ");
        message.append("at base ");
        message.append(baseName);
        message.append(".\n\n\nThere is a list of them:\n\n");
        for (String channel : channelsMap.keySet()) {
            message.append("Channel ");
            message.append(channel);
            message.append(" - ");
            message.append(channelsMap.get(channel));
            message.append("new entries.\n");
        }
        return message.toString();
    }

    /**
     * Compose email sent as notification for Html-type base.
     *
     * @param newContent List with uris containing new content.
     * @param baseName Name of base.
     * @return Composed email content.
     */
    public static String composeHtmlNotification(
            List<String> newContent, String baseName) {
        StringBuilder message = new StringBuilder();
        if (newContent.size() == 1) {
            message.append("The content of site ");
            message.append(newContent.get(0));
            message.append(" at base ").append(baseName);
            message.append(" has changed.");
        } else {
            message.append("The content of ");
            message.append(newContent.size());
            message.append(" pages in base ");
            message.append(baseName);
            message.append(" has changed.\n\n\nThere is a list of them:\n\n");
            int counter = 1;
            for (String url : newContent) {
                message.append(counter++).append(") ");
                message.append(url).append("\n\n");
            }
        }
        return message.toString();
    }
}
